package br.com.hmcontabilidade.onlinev3.business;

import javax.inject.Inject;

import br.com.hmcontabilidade.onlinev3.domain.Bookmark;
import br.com.hmcontabilidade.onlinev3.message.InfoMessages;
import br.com.hmcontabilidade.onlinev3.persistence.BookmarkDAO;
import br.gov.frameworkdemoiselle.annotation.Startup;
import br.gov.frameworkdemoiselle.message.MessageContext;
import br.gov.frameworkdemoiselle.stereotype.BusinessController;
import br.gov.frameworkdemoiselle.template.DelegateCrud;
import br.gov.frameworkdemoiselle.transaction.Transactional;

@BusinessController
public class BookmarkBC extends DelegateCrud<Bookmark, Long, BookmarkDAO> {

	private static final long serialVersionUID = 1L;

	@Inject
	private MessageContext messageContext;

	@Startup
	@Transactional
	public void load() {
		if (findAll().isEmpty()) {
			insert(new Bookmark("Demoiselle Portal", "http://www.frameworkdemoiselle.gov.br"));
			insert(new Bookmark("Demoiselle SourceForge", "http://sf.net/projects/demoiselle"));
			insert(new Bookmark("Twitter", "http://twitter.frameworkdemoiselle.gov.br"));
			insert(new Bookmark("Blog", "http://blog.frameworkdemoiselle.gov.br"));
			insert(new Bookmark("Wiki", "http://wiki.frameworkdemoiselle.gov.br"));
			insert(new Bookmark("Bug Tracking", "http://tracker.frameworkdemoiselle.gov.br"));
			insert(new Bookmark("Forum", "http://forum.frameworkdemoiselle.gov.br"));
			insert(new Bookmark("SVN", "http://svn.frameworkdemoiselle.gov.br"));
			insert(new Bookmark("Maven", "http://repository.frameworkdemoiselle.gov.br"));
			insert(new Bookmark("Downloads", "http://download.frameworkdemoiselle.gov.br"));
		}
	}

	@Override
	public void insert(Bookmark bookmark) {
		super.insert(bookmark);
		messageContext.add(InfoMessages.BOOKMARK_INSERT_OK, bookmark.getDescription());
	}

	@Override
	public void update(Bookmark bookmark) {
		super.update(bookmark);
		messageContext.add(InfoMessages.BOOKMARK_UPDATE_OK, bookmark.getDescription());
	}

	@Override
	public void delete(Long id) {
		super.delete(id);
		messageContext.add(InfoMessages.BOOKMARK_DELETE_OK, id);
	}

}
